package gui;


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;

import types.USER_TYPE;
import user.User;

import database.DBHelper;


/**
 * Login Frame
 * @author warrenshenk
 */
public class HomePageFrame extends JFrame {
	

///////////////////////////////////////////////////////////////////////////////////////
// INSTANCE VARIABLES
///////////////////////////////////////////////////////////////////////////////////////

	private static final long serialVersionUID = 1L;
	private JPanel contentPane, panel_0, panel_1, panel_2, panel_3, panel_4, panel_5;
	private JRadioButton opt1RdBttn, opt2RdBttn;
	private ButtonGroup bttnGroup;
	private JButton nextBttn, logoutBttn;
	private User currUser;

///////////////////////////////////////////////////////////////////////////////////////
// CONSTRUCTORS
///////////////////////////////////////////////////////////////////////////////////////

	/**
	 * Create the frame.
	 */
	public HomePageFrame(User currUser) {
		
		this.currUser = currUser;
		
		setTitle("GT PORT: " + currUser.getName());
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new GridLayout(6, 1, 0, 0));
		
		panel_0 = new JPanel();
		contentPane.add(panel_0);

		panel_1 = new JPanel();
		contentPane.add(panel_1);
		
		panel_2 = new JPanel();
		contentPane.add(panel_2);
		
		panel_3 = new JPanel();
		contentPane.add(panel_3);
		
		panel_4 = new JPanel();
		contentPane.add(panel_4);
		
		panel_5 = new JPanel();
		contentPane.add(panel_5);
		
		opt1RdBttn = new JRadioButton("Personal Information");
		panel_2.add(opt1RdBttn);
		opt1RdBttn.setSelected(true);
		
		opt2RdBttn = new JRadioButton("Student Services");
		panel_2.add(opt2RdBttn);
		
		bttnGroup = new ButtonGroup();
		bttnGroup.add(opt1RdBttn);
		bttnGroup.add(opt2RdBttn);
		
		nextBttn = new JButton("Next");
		nextBttn.addActionListener(nextListener);
		panel_3.add(nextBttn);

		logoutBttn = new JButton("Logout");
		//logoutBttn.addActionListener();
		panel_5.add(logoutBttn);
		
		this.setupPage();
		
	}
	//-----------------------------------------------------------------------------------
	

	
///////////////////////////////////////////////////////////////////////////////////////
// METHODS
///////////////////////////////////////////////////////////////////////////////////////
	public void setupPage() {
		if (currUser.isStudent()) {
		}
		else if (currUser.isInstructor()) {
			opt2RdBttn.setText("Faculty Services");
		}
		else if (currUser.isAdmin()) {
			opt1RdBttn.setText("View Administrative Report");
			opt2RdBttn.setText("Add New Course");
		}

	}
	
///////////////////////////////////////////////////////////////////////////////////////
// BUTTON LISTENERS
///////////////////////////////////////////////////////////////////////////////////////

	private ActionListener nextListener = new ActionListener() {
		
		public void actionPerformed(ActionEvent arg0) {
			if (opt1RdBttn.isSelected()) {
				if (currUser.isStudent()) { // STUDENT PERSONAL INFORMATION
					PersonalInformationFrame pFrame = new PersonalInformationFrame(currUser);
					pFrame.setVisible(true);
					HomePageFrame.this.setVisible(false);
				}
				else if (currUser.isInstructor()) { // FACULTY PERSONAL INFORMATION
					PersonalInformationFrame pFrame = new PersonalInformationFrame(currUser);
					pFrame.setVisible(true);
					HomePageFrame.this.setVisible(false);
					
				}
				else if (currUser.isAdmin()) { // ADMINISTRATIVE REPORT
						
				}
			}
			else if (opt2RdBttn.isSelected()) {
				if (currUser.isStudent()) {
					if (currUser.isInformationSaved()) { // STUDENT SERVICES
						ServiceFrame pFrame = new ServiceFrame(currUser);
						pFrame.setVisible(true);
						HomePageFrame.this.setVisible(false);
					
					}
					else { // PROMPT TO FILL OUT PERSONAL INFORMATION
						new JOptionPane().showMessageDialog(HomePageFrame.this, "You must fill out your personal information first");
					}
				}
				else if (currUser.isInstructor()) {
					if (currUser.isInformationSaved()) { // FACULTY SERVICES
						ServiceFrame pFrame = new ServiceFrame(currUser);
						pFrame.setVisible(true);
						HomePageFrame.this.setVisible(false);
					
					}
					else { // PROMPT TO FILL OUT PERSONAL INFORMATION
						new JOptionPane().showMessageDialog(HomePageFrame.this, "You must fill out your personal information first");
					}
				}
				// (userType == USER_TYPE.ADMIN)
				else { // ADD NEW COURSE
					AdminAddCourse pFrame = new AdminAddCourse(currUser);
					pFrame.setVisible(true);
					HomePageFrame.this.dispose();
				}
			}
		//	else if (opt2RdBttn.isSelected() && )
		}
	};

	

}
